package com.powernode.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.content.Media;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.ai.content.Media;

import java.net.URI;
import java.util.List;

@RestController
public class MultiModelConreoller {

    @Resource
    private ChatClient chatClient;



    @RequestMapping(value = "/ai/multi")
    public Object multi(String msg, String imageUrl) {

        //先构建一个userMessage ，里面传入的就是msg，和图片
        UserMessage userMessage = new UserMessage(msg);
        //调用chatClient的call方法，把userMessage传进去，完后在 指定一个gpt的模型
        ChatClient.ChatClientRequestSpec response = chatClient.prompt(new Prompt(userMessage, OpenAiChatOptions.builder()
                .model(OpenAiApi.ChatModel.GPT_4_O_AUDIO_PREVIEW.getValue())
                .build()));
        ChatClient.CallResponseSpec resp = response.call();
        System.out.println(resp.chatResponse().getResult().getOutput().getText());
        return resp.chatResponse().getResult().getOutput().getText();
    }
    }
